package com.znsd.zl.order.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName RedisUtils
 * @Description TODO
 * @Author zhubin
 * @Date 2020/9/3 20:37
 * @Version v1.0
 */
@Component
public class RedisUtils {
	@Autowired
	private RedisTemplate<String,String> redisTemplate;

	/**
	 * 获取元素
	 * @param key 键
	 * @return  值
	 */
	public String get(String key) {
		return redisTemplate.opsForValue().get(key);
	}

	/**
	 *  设置元素,15分钟过期
	 * @param key 键
	 * @return
	 */
	public boolean set(String key) {
		return redisTemplate.opsForValue().setIfAbsent(key,"1",15, TimeUnit.MINUTES);
	}

	/**
	 * 移除元素
	 * @param key  所有key
	 */
	public Long del(String...key) {
		return redisTemplate.delete(Arrays.asList(key));
	}
}
